package org.wendu.wdoa.security.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wendu.wdoa.common.Utils;
import org.wendu.wdoa.common.page.Page;
import org.wendu.wdoa.security.dto.UserQueryDto;
import org.wendu.wdoa.security.dao.UserDao;
import org.wendu.wdoa.security.service.UserService;
import org.wendu.wdoa.security.model.Role;
import org.wendu.wdoa.security.model.User;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public Page<User> getUserPage(UserQueryDto dto) {

        return Utils.getPage(dto,()->userDao.findUserList(dto));


    }

    @Override
    public void setUserRoles(String u_id, Integer[] roleIds) {
        userDao.deleteAllRolesByUserId(u_id);//根据角色编号删除表t_rm中的角色权限数据
        userDao.insertUserRoles(u_id,roleIds);
    }

    @Override
    public List<Role> getUserRoleList(String userId) {
        return userDao.findUserRoleList(userId);
    }


}
